import { create } from "zustand";
import { TaskProps } from "./types";
import { immer } from "zustand/middleware/immer";

type State = {
  tasks: TaskProps[];
  hoverId: string;
  expendCount: number;
  scrollTop: number;
  scrollLeft: number;
};

type Action = {
  setTasks: (tasks: TaskProps[]) => void;
  setHoverId: (id: string) => void;
  setExpendCount: () => void;
  setScrollTop: (scrollTop: number) => void;
  setScrollLeft: (scrollLeft: number) => void;
};

const useStore = create<State & Action>()(
  immer((set, get) => ({
    tasks: [],
    hoverId: "",
    expendCount: 0,
    scrollTop: 0,
    scrollLeft: 0,
    setHoverId: (id: string) => {
      set({ hoverId: id });
    },
    setTasks: (tasks: TaskProps[]) => {
      set({ tasks: tasks });
    },
    setExpendCount: () => {
      set({ expendCount: get().expendCount + 1 });
    },
    setScrollTop: (scrollTop: number) => {
      set({ scrollTop: scrollTop });
    },
    setScrollLeft: (scrollLeft: number) => {
      set({ scrollLeft: scrollLeft });
    },
  }))
);

export default useStore;
